package com.miao.controller
{
	import com.miao.model.ConfigProxy;
	import com.miao.view.ResourceTreeMediator;
	
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	
	public class LoadConfigCommand extends SimpleCommand implements ICommand
	{
		
		override public function execute(note:INotification):void
		{
			var config:ConfigProxy = facade.retrieveProxy(ConfigProxy.NAME) as ConfigProxy;
			var tree:ResourceTreeMediator = facade.retrieveMediator(ResourceTreeMediator.NAME) as ResourceTreeMediator;
			
			var file:File = new File(File.applicationDirectory.nativePath+"/assets/data/config.xml");
			var fs:FileStream = new FileStream();
			fs.open(file, FileMode.READ);
			var str:String = fs.readMultiByte(fs.bytesAvailable, "utf-8");
			fs.close();
			
			config.setData(new XML(str));
			tree.setData(config.xml);
		}
		
	}
}